import React, {PureComponent} from 'react';
import {StyleSheet, View, Text, TouchableOpacity, Clipboard} from 'react-native';
import ActionSheet from 'react-native-actionsheet';
import SharePlatform from '../../../share/SharePlatform';

export default class extends PureComponent {
    copy = () => {
        let {couponLinkTaoToken, showToast} = this.props;
        if (!couponLinkTaoToken) {
            showToast('请求中，请稍后');
            return;
        }
        Clipboard.setString(couponLinkTaoToken);
        showToast('复制成功');
    };

    showActionSheet = () => {
        this.ActionSheet.show();
    };

    render() {
        const {share} = this.props;
        return (
            <View style={styles.container}>
                <TouchableOpacity style={{width: '48%'}} onPress={this.copy}>
                    <View style={[styles.item, {backgroundColor: '#ffa108'}]}>
                        <Text style={styles.title}>复制淘口令</Text>
                    </View>
                </TouchableOpacity>
                <TouchableOpacity style={{width: '48%'}} onPress={this.showActionSheet}>
                    <View style={[styles.item, {backgroundColor: '#f42f19'}]}>
                        <Text style={styles.title}>分享图片</Text>
                    </View>
                </TouchableOpacity>
                <ActionSheet
                    ref={o => this.ActionSheet = o}
                    title="分享到"
                    options={['微信朋友圈', '微信好友', '取消']}
                    cancelButtonIndex={2}
                    destructiveButtonIndex={1}
                    onPress={(index) => {
                        if (index === 0) {
                            share(SharePlatform.WECHATMOMENT);
                        }
                        if (index === 1) {
                            share(SharePlatform.WECHAT);
                        }
                    }}
                />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        height: 48,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
        backgroundColor: '#fff',
        paddingLeft: 10,
        paddingRight: 10
    },
    item: {
        width: '100%',
        height: 32,
        alignItems: 'center',
        justifyContent: 'center',
        borderRadius: 8
    },
    title: {
        fontSize: 12,
        color: '#fff'
    }
});
